{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "█\r"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Getting uuid of QR code.\n",
      "Downloading QR code.\n",
      "Please scan the QR code to log in.\n",
      "Please press confirm on your phone.\n",
      "Loading the contact, this may take a little while.\n",
      "Login successfully as iced\n"
     ]
    }
   ],
   "source": [
    "import wxpy as wx\n",
    "\n",
    "bot=wx.Bot()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "¹¹【惠万家】水果直销⁻木材新村 › 【惠万家】总团长（招代理） : 就是我们每天团里卖的价格，都是批发价 (Text)\n",
      "home › 朋友 : ！ (Text)\n",
      "home › 朋友 : @iced (Text)\n",
      "¹¹【惠万家】水果直销⁻木材新村 : 你邀请\"母\"加入了群聊   (Note)\n",
      "¹¹【惠万家】水果直销⁻木材新村 : \"母\"与群里其他人都不是微信朋友关系，请注意隐私安全 (Note)\n"
     ]
    }
   ],
   "source": [
    "@bot.register()\n",
    "def print_messages(msg):\n",
    "    print(msg)\n",
    "bot.join()\n",
    "#群\n",
    "wxpy_groups = bot.groups().search('home')\n",
    "wxpy_groups\n",
    "if wx.ensure_one(wxpy_groups) :\n",
    "    ghome=wxpy_groups[0]\n",
    "else:\n",
    "    raise\n",
    "#ghome.send('hello')\n",
    "\n",
    "for member in ghome:\n",
    "    print(member)\n",
    "# is @\n",
    "@bot.register([wxpy_groups], \"TEXT\")\n",
    "def auto_reply(msg):\n",
    "    # 如果是群聊，但没有被 @，则不回复\n",
    "    if isinstance(msg.chat, Group) and not msg.is_at:\n",
    "        return\n",
    "    else:\n",
    "        # 回复消息内容和类型\n",
    "        print(meg)\n",
    "        return '收到消息: {} ({})'.format(msg.text, msg.type)\n",
    "bot.join()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "keywords by textrank:\n",
      "苹果/1.0\n",
      "\n",
      "新疆/0.8177507345858831\n",
      "\n",
      "西瓜/0.684963895815747\n",
      "\n",
      "草莓/0.3839126455067962\n",
      "\n",
      "苹果 新疆 西瓜 草莓\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from jieba import analyse\n",
    "# 引入TextRank关键词抽取接口\n",
    "textrank = analyse.textrank #原始文本\n",
    "text = \"#111 草莓2斤，西瓜2斤，新疆苹果，本地苹果\"\n",
    "print(\"\\nkeywords by textrank:\") # 基于Textrank算法进行关键词提取\n",
    "# topK代表取出前5个词\n",
    "# allowPOS代表词性\n",
    "# withWeight代表输出权重\n",
    "#keywords = textrank(text, topK=5,allowPOS=('n',\"a\"), withWeight=True)\n",
    "keywords = textrank(text, topK=5, withWeight=True)\n",
    "# 输出抽取出的关键词 \n",
    "for keyword,w in keywords:\n",
    "    print(keyword + \"/\" + str(w) + \"\\n\")\n",
    "words = [keyword for keyword, w in keywords if w>0.1]\n",
    "print(\" \".join(words)+\"\\n\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[全模式]:  #/ 我/ 110/ 草莓/ 小果/ 2/ 斤/  / ，/ 百香果/ 不/ 好吃\n"
     ]
    }
   ],
   "source": [
    "import jieba\n",
    "# 全模式\n",
    "text = \"#110草莓小果2斤 ，百香果不好吃\"\n",
    "seg_list = jieba.cut(text, cut_all=False)\n",
    "print(u\"[全模式]: \", \"/ \".join(seg_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sdsd\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
